﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;
using System.Web.UI.MobileControls;
using System.Text;


public partial class admin_manager_user_list : AdminBasePage
{
    string idlist;
    string user;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PopedomValidate(layerid, QUERY);
        user = new AdminBasePage().GetSessionUsersModel().Username;
        if (IsPostBack)
        {
            idlist = "";
            bool BxsChkd = false;
            for (int i = 1; i < GridView1.Rows.Count; i++)
            {
                CheckBox checkbox = (CheckBox)GridView1.Rows[i].FindControl("DeleteThis");
                if (checkbox != null && checkbox.Checked)
                {
                    BxsChkd = true;
                    System.Web.UI.WebControls.Label lable = (System.Web.UI.WebControls.Label)GridView1.Rows[i].Cells[0].FindControl("Label1");
                    idlist = idlist + lable.Text + ",";
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
        }
        else
        {
            header.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);
            BindData();
        }

    }
    //删除
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        this.PopedomValidate(Layerid, DEL);
        string idlists = idlist;
        if (idlists.Trim().Length == 0)
            return;
        if (new UsersBll().DeleteList(idlists))
        {

            this.insertLog(user + "删除了用户id为" + idlists+"的用户");
        }
        BindData();
    }
    //数据绑定
    public void BindData()
    {
        DataSet ds = new DataSet();
        ds = new UsersBll().GetList("");       
        GridView1.DataSource = ds;
        GridView1.DataBind();

    }
    //protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    //{
    //    System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)e.Item.FindControl("username");
    //    HyperLink a = (HyperLink)e.Item.FindControl("a");

    //    a.NavigateUrl = string.Format("user_modify.aspx?layerid={0}&name={1}", Layerid, label.Text);
    //    if (label.Text == "admin")
    //    {
    //        // //HtmlLink a = (HtmlLink)e.Item.FindControl("a");
    //        //HyperLink a = (HyperLink)e.Item.FindControl("a");
    //        // //HtmlAnchor a = (HtmlAnchor)Repeater1.Items[i].FindControl("a");
    //        // a.Visible = false;
    //    }
    //}
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        //System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)e..FindControl("username");
        //HyperLink a = (HyperLink)e.Item.FindControl("a");
        //a.NavigateUrl = string.Format("user_modify.aspx?layerid={0}&name={1}", Layerid, label.Text);
    }
    protected void GridView1_DataBinding(object sender, EventArgs e)
    {
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string label = e.Row.Cells[2].Text;
            HyperLink a = (HyperLink)e.Row.FindControl("a");
            a.NavigateUrl = string.Format("user_modify.aspx?layerid={0}&name={1}", Layerid, label);
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindData();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {         
        GridViewRow gvr = GridView1.BottomPagerRow;
        System.Web.UI.WebControls.TextBox textbox = (System.Web.UI.WebControls.TextBox)gvr.FindControl("txtNewPageIndex");
        System.Web.UI.WebControls.Label lblcount = (System.Web.UI.WebControls.Label)gvr.FindControl("lblPageCount");
        //if (int.Parse(textbox.Text) >= 1)
        //{
        //    GridView1.PageIndex = int.Parse(textbox.Text) - 1;            
        //}
        //else
        //{
        //    GridView1.PageIndex = 0;
        //}
        int index;
        if(int.TryParse(textbox.Text,out index))
        {
            if (index >= 1)
            {
                GridView1.PageIndex = index - 1;
            }
            else
                GridView1.PageIndex = 0;
        }       
        else
        {
            ClientScript.RegisterClientScriptBlock(Page.GetType(), Guid.NewGuid().ToString(), "alert('输入的数字非法')");
        }
        BindData();
    }
  
    
}
